<?php

class PurifierManager
{

    protected static $instance;
    protected $_options;
    protected $_purify;

    public static function getInstance()
    {
	if (is_null(self::$instance)) {
	    self::$instance = new PurifierManager();
	}
	return self::$instance;
    }

    public function setOptions($options)
    {
	$this->_options = $options;
	return $this;
    }

    public function getOptions()
    {
	if (!$this->_options) {
	    $this->_options = array('URI.AllowedSchemes' => array(
		    'http' => true,
		    'https' => true,
		),		
		'HTML.Nofollow' => true,
		'HTML.Allowed' => 'a[href],b,strong,i,em,u'
	    );
	}
	return $this->_options;
    }

    public function getPufiry()
    {
	if ($this->_purify === null) {
	    $this->_purify = new CHtmlPurifier();
	}
	return $this->_purify;
    }

    public function filter($content)
    {
	$purifier = $this->getPufiry();
	$purifier->options = $this->getOptions();
	if (is_array($content)) {
	    foreach ($content as $key => $value) {
		$content[$key] = $purifier->purify($value);
	    }
	    return $content;
	}
	return $purifier->purify($content);
    }

}

?>
